package io;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
import org.w3c.dom.ls.LSOutput;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 对象流
 * 是一种高级流，作用是进行对象序列化与反序列化
 *
 * 序列化
 */
public class OOSDemo {
    public static void main(String[] args) throws IOException {
        String name = "刘仓";
        int age = 55;
        String gender = "男";
        String[] otherInfo = {"技术好","技术超好","nice","perfect"};
        Person p = new Person(name,age,gender,otherInfo);
        System.out.println(p);
        //将person对象写入文件person.obj
        FileOutputStream fos = new FileOutputStream("person.obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        //writeObject()会将对象结构转换为一组字节后写出。
        //java.io.NotSerializableException--原因是该类没有实现 Serializable 接口
        oos.writeObject(p);
        System.out.println("读写完毕");
        oos.close();
    }
}
